package com.handinfo.android.ui.window;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.view.animation.Animation;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWBitmap;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.core.net.GameProtocol;
import com.handinfo.android.core.object.Actor;
import com.handinfo.android.game.Cell;
import com.handinfo.android.game.Role;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWExternalDraw;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWAnimationBox;
import com.handinfo.android.uicontrols.controls.DWControl;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.utils.Tools;

public class UILetou implements IUIWindows{
	private DWImageBox m_img;
	private DWFrame m_frame;
	private Bitmap m_bk;
	private Bitmap m_yaoji;
	private Bitmap m_jinku;
	private Bitmap m_wan;
	private Bitmap m_wans;
	private Bitmap m_cjhongdi;
	private Bitmap m_cjhongding;
	private Bitmap m_choujiangji;
	private Bitmap m_qian;
	private Bitmap m_shuzi;
	private Bitmap[] m_icon;
	private Bitmap m_jkjq;
	private Bitmap m_jiangli;
	private Bitmap m_xz01;
	private Bitmap m_xz02;
	private int icon = 6;
	private long m_money =  999999999;//奖池金额
	private long m_money2 = 9999;//获奖金额
	private int m_itemnum = 0;//道具个数
	private byte m_sxnum = 0;//道具所需个数
	private DWImageBox closeImgBoxs;
	private DWImageBox img1b;
	private String m_itemkey;
	private String m_itemname = "落宝金币";
	private DWTextbox tbshuzi;
	private DWAnimationBox img3d;
	public void init() {
		// TODO Auto-generated method stub
		m_jkjq =  UIWindows.createImage("/img/newui/jinkujinqian_1.gnp");
		m_icon = new Bitmap[icon];
		m_icon[0] =  UIWindows.createImage("/img/newui/caishenlibao_1.gnp");
		m_icon[1] =  UIWindows.createImage("/img/newui/baifenlingdianyi_1.gnp");
		m_icon[2] =  UIWindows.createImage("/img/newui/baifenwu_1.gnp");
		m_icon[3] =  UIWindows.createImage("/img/newui/baifener_1.gnp");
		m_icon[4] =  UIWindows.createImage("/img/newui/baifensanshi_1.gnp");
		m_icon[5] =  UIWindows.createImage("/img/newui/jinzhuangsuipian_2.gnp");
		
		m_bk = UIWindows.createImage("/img/newui/caishendt_1.gnp");
		m_yaoji = UIWindows.createImage("/img/newui/choujiangji_1.gnp");
		m_jinku = UIWindows.createImage("/img/newui/jinkudt_1.gnp");
		m_wan = UIWindows.createImage("/img/newui/jinkuzi_1.gnp");
		m_wans = UIWindows.createImage("/img/newui/wanzi_1.gnp");
		m_cjhongdi = UIWindows.createImage("/img/newui/cjhongdi_1.gnp");
		m_cjhongding = UIWindows.createImage("/img/newui/cjhongding_1.gnp");
		m_choujiangji = UIWindows.createImage("/img/newui/choujiangji_2.gnp");
		m_qian = UIWindows.createImage("/img/newui/luobaojinbi_1.gnp");	
		m_shuzi = UIWindows.createImage("/img/newui/shuzi_6.gnp");	
		
		m_xz01 =  UIWindows.createImage("/img/newui/fanhuianniu_2.gnp");	
		m_xz02 =  UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");	
		
		m_jiangli = UIWindows.createImage("/img/newui/huojiangdt_1.gnp");	
	
	}
	public void frame(){
		m_frame = new DWFrame();
		m_frame.setPoint(0,0);
		m_frame.setShowWideHigh(DWGameManager.Screen_Width, DWGameManager.Screen_Height );
		m_frame.m_null_frame = false;
		m_frame.setClickClose(false);
		
		//叉子
		closeImgBoxs=new DWImageBox(m_xz01);
		closeImgBoxs.addListener(new DWListener() {			
			public void OnDoubleClick(){ 
			}
			public void OnClick()
			{
				if(!m_yaojiang){
					DWControlsManager.getInstance().removeControl(m_frame);
				}
			}
		});
		closeImgBoxs.setNearAnchor(m_frame, Tools.RIGHT_TOP, Tools.RIGHT_TOP);
		m_frame.addControl(closeImgBoxs);

		//绘制摇奖背景
		DWImageBox img2 = new DWImageBox(m_bk);
		img2.setNearAnchor(m_frame, Tools.LEFT_TOP, Tools.LEFT_TOP,m_frame.getShowWidth()-m_bk.getWidth()>>1,(m_frame.getShowHeight()-m_bk.getHeight()>>1)-20);
		img2.setTouch(false);
		m_frame.addControl(img2);
		
		//绘制金库背景
		DWImageBox img1 = new DWImageBox(m_jinku);
		img1.setNearAnchor(m_frame, Tools.LEFT_TOP, Tools.LEFT_TOP,5,5);
		img1.setTouch(false);
		m_frame.addControl(img1);
		//绘制金库字
		DWImageBox img1a = new DWImageBox(m_wan);
		img1a.setNearAnchor(img1, Tools.LEFT_TOP, Tools.LEFT_TOP,40,36);
		img1a.setTouch(false);
		m_frame.addControl(img1a);
		
		int digit = 0;
		if(m_money>9999){
			long num = m_money/10000;
			byte[] nums = new byte[20];
			
			for (int i = 0; i < 20; i++) {
				long m = num % 10;
				num /= 10;
				nums[i] = (byte) m;
				if (num == 0) {
					digit = i + 1;
					break;
				}
			}
		}else{
			long num = m_money2;
			byte[] nums = new byte[20];
			for (int i = 0; i < 20; i++) {
				long m = num % 10;
				num /= 10;
				nums[i] = (byte) m;
				if (num == 0) {
					digit = i + 1;
					break;
				}
			}
		}
		
		//绘制数字
		DWImageBox shuzi = new DWImageBox(95,m_wan.getHeight());
		shuzi.setNearAnchor(img1a, Tools.LEFT_TOP, Tools.LEFT_TOP,95,5);
		shuzi.addExternalDraw(new DWExternalDraw() {
			public void externalDraw(DWGraphics g, int x, int y) {
				if(m_money>9999){
					Tools.drawNumber(g, m_shuzi, x, y, m_shuzi.getWidth()/11,
						m_shuzi.getHeight(), 1, 1, m_money/10000, 1, Tools.LEFT_VCENTER, false);
				}else{
//					Tools.debugPrintln("m_money:"+m_money);
					Tools.drawNumber(g, m_shuzi, x, y, m_shuzi.getWidth()/11,
							m_shuzi.getHeight(), 1, 1, m_money, 1, Tools.LEFT_VCENTER, false);
				}
			}
		});
		m_frame.addControl(shuzi);
		//绘制万字
		img1b = new DWImageBox(m_wans);
		img1b.setNearAnchor(shuzi, Tools.LEFT_TOP, Tools.LEFT_TOP,digit*(m_shuzi.getWidth()/11)-8,-5);
		img1b.setTouch(false);
		if(m_money>9999){
			img1b.setShow(true);
		}else{
			img1b.setShow(false);
		}
		m_frame.addControl(img1b);

		//绘制道具金钱数字
		tbshuzi = new DWTextbox("<mark c=FFC004>"+" X "+m_itemnum+"</mark>");
		
		//绘制老虎机
		DWImageBox img3 = new DWImageBox(m_yaoji);
		img3.setNearAnchor(img2, Tools.LEFT_TOP, Tools.LEFT_TOP,155,190);
		img3.setTouch(false);
		//绘制手柄
		DWImageBox img3c = new DWImageBox(m_choujiangji);
		img3c.setNearAnchor(img3, Tools.LEFT_TOP, Tools.LEFT_TOP,386,-25);
		img3c.addListener(new DWListener() {
			public void OnDoubleClick() {
			}
			public void OnClick() {
				// TODO Auto-generated method stub
				Role role = DWGameManager.getInstance().m_role;
				if(!m_yaojiang&&m_yao){

						if(m_itemnum>=m_sxnum){
							if(role.m_vip_lv>0){

								sendREQUESTLOTTERY();
					
							}else{
								DWGameManager.getInstance().addSystemInfo(
										DWGameManager.SYSTEM_INFO_TYPE_B, "您不是VIP无法参加该活动！");
							}
						}else{
							DWGameManager.getInstance().addSystemInfo(
									DWGameManager.SYSTEM_INFO_TYPE_B, "摇奖失败，"+m_itemname+"不足！");
						}
				}
			}
		});
		//绘制红背景
		DWImageBox img3a = new DWImageBox(m_cjhongdi);
		img3a.setNearAnchor(img3, Tools.LEFT_TOP, Tools.LEFT_TOP,35,30);
		img3a.setTouch(false);
		m_frame.addControl(img3a);
		
		m_img = new  DWImageBox(img3a.getShowWidth(),img3a.getShowHeight());
		m_img.setNearAnchor(img3a, Tools.LEFT_TOP, Tools.LEFT_TOP);
		m_img.addExternalDraw(new DWExternalDraw() {
			public void externalDraw(DWGraphics g, int x, int y) {
				// TODO Auto-generated method stub
				draw(g, x, y);
			}
		});
		m_img.setTouch(false);
		m_frame.addControl(m_img);
		//绘制透明背景
		DWImageBox img3b = new DWImageBox(m_cjhongding);
		img3b.setTouch(false);
		img3b.setNearAnchor(img3, Tools.LEFT_TOP, Tools.LEFT_TOP,35,30);
		m_frame.addControl(img3b);
		m_frame.addControl(img3);
		
		//绘制抽奖杆动画的
		com.handinfo.android.core.object.Animation anim = UIWindows.createAnimation("/anim/choujianggan_1.anim");
		Actor act = new Actor(anim);
		img3d = new DWAnimationBox(act);
		img3d.setNearAnchor(img3c, Tools.LEFT_TOP, Tools.LEFT_TOP,-29,-125);
		img3d.setTouch(false);
		m_frame.addControl(img3d);
		
		m_frame.addControl(img3c);
		
		//绘制道具金钱图标
		DWImageBox qian = new DWImageBox(m_qian);
		qian.setNearAnchor(m_frame, Tools.LEFT_TOP, Tools.LEFT_TOP,m_frame.getShowWidth()-160,m_frame.getShowHeight()-80);
		qian.setTouch(false);
		m_frame.addControl(qian);
		//绘制道具金钱数字
		tbshuzi.setNearAnchor(qian, Tools.LEFT_TOP, Tools.LEFT_TOP,qian.getShowWidth(),qian.getShowHeight()-tbshuzi.getShowHeight()>>1);
		tbshuzi.setTouch(false);
		m_frame.addControl(tbshuzi);
		
		//绘制底部说明文字
		final DWImageBox imgstr = new DWImageBox(m_frame.getShowWidth(),m_frame.getShowHeight());
		imgstr.setNearAnchor(m_frame, Tools.LEFT_TOP, Tools.LEFT_TOP);
		imgstr.addExternalDraw(new DWExternalDraw() {
			
			public void externalDraw(DWGraphics g, int x, int y) {
				g.setColor(0xAA000000);
				String str="使用落宝金钱参与抽奖,只有VIP可参与"; 
				
				g.fillRect(x+160, y+imgstr.getShowHeight() - (g.getFontHeight()+4), imgstr.getShowWidth()-320, g.getFontHeight()+4);
				g.drawString(str, 0xFFCCAF50, x+160+((int)((imgstr.getShowWidth()-320)-DWFont.getDefaultFont().stringWidth(str))>>1),
						y+imgstr.getShowHeight() - (g.getFontHeight()+2), 0);
			}
		});
		imgstr.setTouch(false);
		m_frame.addControl(imgstr);
	
	}
	private int times = 8000;
	private boolean m_yao=true;
	private boolean m_yaojiang=false;
	private int m_speed =1;
	private int m_ys=0;
	private int m_time=0;
	private boolean m_zhuan=true;
	private byte m_win=0;//中奖号码
	private boolean m_ting=false;
	public void draw(DWGraphics g, int x, int y){
		int y1 = y-34;
		int x1 = x+20;
		int y2 = y1-((m_icon.length)*m_jkjq.getHeight()+10);
		if(m_yaojiang){
			m_ys += m_speed;
			if(m_zhuan){
				times=8000;
				if(m_speed<40){
					if(m_time<1){
						m_time++;
					}else{
						m_speed++;
						m_time=0;
					}
				}else{
					m_zhuan=false;
				}
			}else{
				if(m_jieshou||m_shibai){
					if(m_speed>5){
						if(m_time<1){
							m_time++;
						}else{
							m_speed--;
							m_time=0;
						}
					}else{
						if((y1+(m_win)*m_jkjq.getHeight()+10+m_ys)==(y1+m_jkjq.getHeight()+10)||(y2+(m_win)*m_jkjq.getHeight()+10+m_ys)==(y1+m_jkjq.getHeight()+10)){
							zhengque();
						}
					}
					if(m_speed<=10){
						if((y1+(m_win)*m_jkjq.getHeight()+10+m_ys)==(y1+m_jkjq.getHeight()+10)||(y2+(m_win)*m_jkjq.getHeight()+10+m_ys)==(y1+m_jkjq.getHeight()+10)){
							zhengque();
						}
					}
					if(m_speed<=5&&m_speed>0){
						if(((y1+(m_win)*m_jkjq.getHeight()+10+m_ys)+5>=(y1+m_jkjq.getHeight()+10)&&(y1+(m_win)*m_jkjq.getHeight()+10+m_ys)+5<=(y1+2*m_jkjq.getHeight()+10))
								||((y2+(m_win)*m_jkjq.getHeight()+10+m_ys)+5>=(y1+m_jkjq.getHeight()+10)&&(y2+(m_win)*m_jkjq.getHeight()+10+m_ys)+5<=(y1+2*m_jkjq.getHeight()+10))){
							m_speed = 1;
						}
						if((y1+(m_win)*m_jkjq.getHeight()+10+m_ys)==(y1+m_jkjq.getHeight()+10)||(y2+(m_win)*m_jkjq.getHeight()+10+m_ys)==(y1+m_jkjq.getHeight()+10)){
							zhengque();
						}
					}
				}else{
			
					if(m_ting){
						if(m_time<1){
							m_time++;
						}else{
							m_speed--;
							m_time=0;
						}
						if(m_speed<=0){
							m_ting = false;
							m_yaojiang = false;
							m_time = 0;
							closeImgBoxs.setShow(true);
							m_jieshou = false;
							m_shibai = false;
							m_yao = true;
							Role role = DWGameManager.getInstance().m_role;
							Cell cell = role.getCellByKeyForRoleBagColumn(m_itemkey);
							img3d.setShow(true);
							if (cell != null) {
								Item item = cell.m_item;
								m_itemnum =  role.getItemCountManager(Cell.TYPE_COLUMN_ROLEBAG, m_itemkey);
								tbshuzi.setText("<mark c=FFC004>"+" X "+m_itemnum+"</mark>");
							}
						}
					}else{
						if(times<=0){
							times=8000;
							m_ting = true;
	
							DWGameManager.getInstance().addSystemInfo(
									DWGameManager.SYSTEM_INFO_TYPE_B, "亲您的网络出现异常，本次摇奖失败，请重试！");
						}else{	
							times--;
						}
					}
				}
			}
		}
		
		for(int i=0;i<m_icon.length;i++){
			if(i>0&&i<5){
				g.drawBitmap(m_jkjq, x1, y2+i*m_jkjq.getHeight()+10+m_ys, 0);
				g.drawBitmap(m_icon[i], x1+m_jkjq.getWidth()+5, y2+i*m_jkjq.getHeight()+10+m_ys, 0);
			}else{
				g.drawBitmap(m_icon[i], x1, y2+i*m_jkjq.getHeight()+10+m_ys, 0);
			}
		}
		for(int i=0;i<m_icon.length;i++){
			if(i>0&&i<5){
				g.drawBitmap(m_jkjq, x1, y1+i*m_jkjq.getHeight()+10+m_ys, 0);
				g.drawBitmap(m_icon[i], x1+m_jkjq.getWidth()+5, y1+i*m_jkjq.getHeight()+10+m_ys, 0);
			}else{
				g.drawBitmap(m_icon[i], x1, y1+i*m_jkjq.getHeight()+10+m_ys, 0);
			}
		}
		if((y2+m_ys)>=y1){
			m_ys = 0;
		}
	}
	public void zhengque(){
		m_speed = 0;
		if(m_time<10){
			m_time++;
		}else{
			if(m_shibai){
				m_yaojiang = false;
				m_time = 0;
				closeImgBoxs.setShow(true);
				m_jieshou = false;
				m_shibai = false;
				m_yao = true;
				Role role = DWGameManager.getInstance().m_role;
				Cell cell = role.getCellByKeyForRoleBagColumn(m_itemkey);
				img3d.setShow(true);
				if (cell != null) {
					Item item = cell.m_item;
					m_itemnum =  role.getItemCountManager(Cell.TYPE_COLUMN_ROLEBAG, m_itemkey);
					tbshuzi.setText("<mark c=FFC004>"+" X "+m_itemnum+"</mark>");
				}
				if(states==0){
					m_shibai = true;
					DWGameManager.getInstance().addSystemInfo(
							DWGameManager.SYSTEM_INFO_TYPE_B, "操作失败！");
					return;
				}else if(states == 2){
					m_shibai = true;
					DWGameManager.getInstance().addSystemInfo(
							DWGameManager.SYSTEM_INFO_TYPE_B, "摇奖失败，背包已满！");
					return;
				}else if(states == 3){
					m_shibai = true;
					DWGameManager.getInstance().addSystemInfo(
							DWGameManager.SYSTEM_INFO_TYPE_B, "摇奖失败，道具不足！");
					return;
				}else if(states == 4){
					m_shibai = true;
					DWGameManager.getInstance().addSystemInfo(
							DWGameManager.SYSTEM_INFO_TYPE_B, "摇奖失败，您VIP等级不足！");
					return;
				}
			}else{
				img3d.setShow(true);
				m_yaojiang = false;
				m_time = 0;
				closeImgBoxs.setShow(true);
				m_jieshou = false;
				m_shibai = false;
				sendGETLOTTERYPRIZE();
			}

		}
	}
	public void jiangli(){
		final DWFrame	frame = new DWFrame();
		frame.setPoint(0,0);
		frame.setShowWideHigh(DWGameManager.Screen_Width, DWGameManager.Screen_Height );
		frame.m_null_frame = true;
		frame.setClickClose(false);
		DWImageBox img = new DWImageBox(m_jiangli);
		img.setNearAnchor(frame, Tools.LEFT_TOP, Tools.LEFT_TOP,frame.getShowWidth()-img.getShowWidth()>>1,frame.getShowHeight()-img.getShowHeight()>>1);
		img.setTouch(false);
		frame.addControl(img);
		//叉子
		DWImageBox closeImgBox=new DWImageBox(m_xz02);
		closeImgBox.addListener(new DWListener() {			
			public void OnDoubleClick(){ 
			}
			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(frame);
			}
		});
		closeImgBox.setNearAnchor(img, Tools.RIGHT_VCENTER, Tools.RIGHT_TOP,closeImgBox.getShowWidth()>>1,0);
		frame.addControl(closeImgBox);
		switch (m_win) {
		case 0:
			DWImageBox img2 = new DWImageBox(m_icon[0]);
			img2.setNearAnchor(img, Tools.LEFT_TOP, Tools.LEFT_TOP,48,110);
			img2.setTouch(false);
			frame.addControl(img2);
			break;
		case 1:
		case 2:
		case 3:
		case 4:
			int digit = 0;
			if(m_money2>9999){
				long num = m_money2/9999;
				byte[] nums = new byte[20];
				
				for (int i = 0; i < 20; i++) {
					long m = num % 10;
					num /= 10;
					nums[i] = (byte) m;
					if (num == 0) {
						digit = i + 1;
						break;
					}
				}
			}else{
				byte[] nums = new byte[20];
				long num = m_money2;
				for (int i = 0; i < 20; i++) {
					long m = num % 10;
					num /= 10;
					nums[i] = (byte) m;
					if (num == 0) {
						digit = i + 1;
						break;
					}
				}
			}
			DWImageBox img1bs = new DWImageBox(m_wans);
			//绘制数字
//			Tools.debugPrintln("位数："+digit);
			DWImageBox shuzi = new DWImageBox(95,m_wan.getHeight());
			if(m_money2>9999){
				shuzi.setNearAnchor(img, Tools.LEFT_TOP, Tools.LEFT_TOP,img.getShowWidth()-(digit*(m_shuzi.getWidth()/11)+img1bs.getShowWidth()-12)>>1,125);
			}else{
				shuzi.setNearAnchor(img, Tools.LEFT_TOP, Tools.LEFT_TOP,img.getShowWidth()-(digit*(m_shuzi.getWidth()/11))>>1,125);
			}
			shuzi.addExternalDraw(new DWExternalDraw() {
				public void externalDraw(DWGraphics g, int x, int y) {
					if(m_money2>9999){
						Tools.drawNumber(g, m_shuzi, x, y, m_shuzi.getWidth()/11,
							m_shuzi.getHeight(), 1, 1, m_money2/10000, 1, Tools.LEFT_TOP, false);
					}else{
//						Tools.debugPrintln("m_money2:"+m_money2);
						Tools.drawNumber(g, m_shuzi, x, y, m_shuzi.getWidth()/11,
								m_shuzi.getHeight(), 1, 1, m_money2, 1, Tools.LEFT_TOP, false);
					}
				}
			});
			frame.addControl(shuzi);
			
			//绘制万字
	
			img1bs.setNearAnchor(shuzi, Tools.LEFT_TOP, Tools.LEFT_TOP,digit*(m_shuzi.getWidth()/11),-5);
			img1bs.setTouch(false);
			if(m_money2>9999){
				img1bs.setShow(true);
			}else{
				img1bs.setShow(false);
			}
			frame.addControl(img1bs);
			
			break;


		case 5:
			DWImageBox img3 = new DWImageBox(m_icon[5]);
			img3.setNearAnchor(img, Tools.LEFT_TOP, Tools.LEFT_TOP,48,110);
			img3.setTouch(false);
			frame.addControl(img3);
			break;

		default:
			break;
		}
		DWControlsManager.getInstance().addControl(frame);
		
	}
	public void open(byte index) {
		// TODO Auto-generated method stub
		Tools.debugPrintln("进入抽奖界面");
		frame();
		DWControlsManager.getInstance().addControl(m_frame);
	}

	public void close(byte index) {
		// TODO Auto-generated method stub
		
	}

	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	public void logic() {
		// TODO Auto-generated method stub
		
	}
	// 接收10600
	public void recvOpenLOTTERY(DataInputStream dis) throws IOException {
		Tools.debugPrintln("接收指令" + GameProtocol.SC_OpenLOTTERY + "!");
		byte state = dis.readByte();
		if(state!=1){
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "开启失败!");
			return;
		}
		m_money = dis.readLong();
		m_itemkey = dis.readUTF();
		m_sxnum = dis.readByte();
		Tools.debugPrintln("10600m_money+"+m_money);
		Role role = DWGameManager.getInstance().m_role;
		Cell cell = role.getCellByKeyForRoleBagColumn(m_itemkey);
		if (cell != null) {
			Item item = cell.m_item;
			m_itemnum =  role.getItemCountManager(Cell.TYPE_COLUMN_ROLEBAG, m_itemkey);
			m_itemname = item.m_name;
			Tools.debugPrintln("m_itemname"+m_itemname);
		}
		open((byte)0);
	}
	private boolean m_jieshou=false;
	private boolean m_shibai=false;
	private byte states = 0;
	// 接收10601
	public void recvREQUESTLOTTERY(DataInputStream dis) throws IOException {
		Tools.debugPrintln("接收指令" + GameProtocol.SC_REQUESTLOTTERY + "!");
	
	    states = dis.readByte();
		if(states==0){
			m_shibai = true;
			m_win = (byte)Tools.random(0, 5);
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "操作失败！");
			return;
		}else if(states == 2){
			m_shibai = true;
			m_win = (byte)Tools.random(0, 5);
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "摇奖失败，背包已满！");
			return;
		}else if(states == 3){
			m_shibai = true;
			m_win = (byte)Tools.random(0, 5);
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "摇奖失败，道具不足！");
			return;
		}else if(states == 4){
			m_shibai = true;
			m_win = (byte)Tools.random(0, 5);
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "摇奖失败，您VIP等级不足！");
			return;
		}else{
			m_shibai = false;
			m_itemnum-=m_sxnum;
			tbshuzi.setText("<mark c=FFC004>"+" X "+m_itemnum+"</mark>");
			m_speed = 1;
			m_yaojiang = true;
			m_zhuan=true;
			Tools.debugPrintln("进入m_yaojiang");
			closeImgBoxs.setShow(false);
			m_yao=false;
			img3d.setShow(false);
		}
		m_win =  dis.readByte();
//		if(states!=1){
//			m_win = (byte)Tools.random(0, 5);
//		}
		m_jieshou = true;
	}
	// 接收10602	
	public void recvGETLOTTERYPRIZE(DataInputStream dis) throws IOException {
		Tools.debugPrintln("接收指令" + GameProtocol.SC_GETLOTTERYPRIZE + "!");
		byte state = dis.readByte();
		if(state==0){
			m_yao=true;
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "领取失败!");
			return;
		}else if(state==2){
			m_yao=true;
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "领取失败!");
			return;
		}
		m_money2 = dis.readLong();
		m_money = dis.readLong();
		Tools.debugPrintln("10602m_money2+"+m_money2);
		Tools.debugPrintln("10602m_money+"+m_money);
		Role role = DWGameManager.getInstance().m_role;
		Cell cell = role.getCellByKeyForRoleBagColumn(m_itemkey);
		if (cell != null) {
			Item item = cell.m_item;
			m_itemnum =  role.getItemCountManager(Cell.TYPE_COLUMN_ROLEBAG, m_itemkey);
			tbshuzi.setText("<mark c=FFC004>"+" X "+m_itemnum+"</mark>");
		}
		if(m_money>9999){
			img1b.setShow(true);
		}else{
			img1b.setShow(false);
		}
		jiangli();
		m_yao=true;
	}
	//发送10600
	public void sendOpenLOTTERY(){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {

			dos.writeByte(0);


			DWGameManager
					.getInstance()
					.getConnection()
					.sendMessage(0, GameProtocol.CS_OpenLOTTERY,
							baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_OpenLOTTERY + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//发送10601
	public void sendREQUESTLOTTERY(){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {

			dos.writeByte(0);


			DWGameManager
					.getInstance()
					.getConnection()
					.sendMessage(0, GameProtocol.CS_REQUESTLOTTERY,
							baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_REQUESTLOTTERY + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//发送10602
	public void sendGETLOTTERYPRIZE(){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {

			dos.writeByte(0);


			DWGameManager
					.getInstance()
					.getConnection()
					.sendMessage(0, GameProtocol.CS_GETLOTTERYPRIZE,
							baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_GETLOTTERYPRIZE + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
